<%@page import="domain.BlogFile"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="getools4me.UserManager"%>
<%@page import="java.util.List"%>
<%@page import="getools4me.BlogManager"%>
<%@page import="utils.DateUtils"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="/blog/css/common.css" />
<link rel="stylesheet" type="text/css" href="/blog/css/menu.css" />
<link rel="stylesheet" type="text/css" href="/blog/css/bloglist.css" />
<script type="text/javascript" src="/blog/js/common.js"></script>

<title>Blog</title>
</head>
<body>

	<div class="menu">
		<ul>
			<li><a href="/blog/page/home.jsp">Home</a>
			</li>
			<li><a href="/blog/page/all.jsp">All</a>
			</li>
			<li>
				<%if(UserManager.isLogin()){ %><a
				href="<%=UserManager.getLogoutURL(request)%>">Logout</a>
				<%}else{ %><a href="<%=UserManager.getLoginURL(request)%>">Login</a>
				<%} %>
			</li>
			<li>
				<%if(UserManager.isAdmin()){ %> <a href="/blog/page/new.jsp">New</a>
				<%} %>
			</li>
		</ul>
	</div>



	<div class="bloglist">

		<div class="list">
			<%
		
		String pageNum_str = request.getParameter("page");
		int pageNum = 0;
		if(pageNum_str!=null && pageNum_str.matches("\\d+")){
			pageNum = Integer.valueOf(pageNum_str);
		}
		List<BlogFile> list = BlogManager.getPageList(pageNum);
		for(int i=0;i<list.size();i++){
			BlogFile file = list.get(i);
			long blogID = file.getId();
			long lastModifiedDate = file.getLastModifiedDate();
	%>
			<div class="preview">
				<div class="article_title">
					<a href="/blog/page/detail.jsp?blogID=<%=blogID%>"> <span
						id="<%=blogID%>.title" class="safeString"><%= new String(file.getTitle()) %></span>
					</a> <sub class="commentCount"><%=BlogManager.getBlogCommentIDList(file.getId()).size()%></sub>
				</div>
				<div class="article_content">
					<pre id="<%=blogID%>.content" class="safeString"><%=new String(file.getContent())%></pre>
				</div>
				<div class="article_utils">
					<div class="timestamp">
						<span><%=DateUtils.format("yyyy.MMM.",lastModifiedDate)%></span><span
							class="days"><%=DateUtils.format("dd",lastModifiedDate)%></span>
						&nbsp;&nbsp;<span><%=DateUtils.format("HH:mm:ss",lastModifiedDate)%></span>
					</div>


				</div>
			</div>
			<%} %>
		</div>


		<div class="page_navigator">

			<div class="prviousPage">
				<%if(pageNum>0){ %>
				<a href="/blog/page/home.jsp?page=<%=pageNum-1%>">Previous Page</a>
				<%} %>
			</div>

			<div class="nextPage">
				<%	list = BlogManager.getPageList(pageNum+1);
				if(list.size()>0){%>
				<a href="/blog/page/home.jsp?page=<%=pageNum+1%>">Next Page</a>
				<%}else{ %>
				End
				<%} %>
			</div>

		</div>


	</div>

	<div class="south">
		<div class="footer">
			<iframe class="footer" src="/footer.html" frameborder="0"
				width="100%"></iframe>
		</div>
	</div>

	<script type="text/javascript">
		new Common().convertSafeStringClassElementInnerHtmlFromUnicodeToSafeString(document);
	</script>



</body>
</html>